package com;

import java.util.Scanner;

public class minInteger {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int t=0;t<T;t++) {
            int n = sc.nextInt();
            int most = 0;
            int sum = 0;
            int temp = 0;
            int last = 0;
            for(int i = 0;i<n;i++) {
                int a = sc.nextInt();
                if(a == last) {
                    temp++;
                }else {
                    temp = 1;
                }
                last = a;
                if(temp>sum) {
                    sum = temp;
                    most = a;
                }
            }
            System.out.println(most);
        }
        sc.close();
    }
}



